export const setItem = (key, val) => {
	if (typeof val == 'object') {
		val = JSON.stringify(val);
	}
	window.localStorage.setItem(key, val);
};

export const getItem = (key) => {
	let res = window.localStorage.getItem(key);
	try {
		return JSON.parse(res);
	} catch (error) {
		return res;
	}
};

export const removeItem = (key) => {
	window.localStorage.removeItem(key);
};

export const removeAllItem = () => {
	window.localStorage.clear();
};

export const setItems = (key, val) => {
	if (typeof val == 'object') {
		val = JSON.stringify(val);
	}
	window.sessionStorage.setItem(key, val);
};

export const getItems = (key) => {
	let res = window.sessionStorage.getItem(key);
	try {
		return JSON.parse(res);
	} catch (error) {
		return res;
	}
};

export const removeItems = (key) => {
	window.sessionStorage.removeItem(key);
};

export const removeAllItems = () => {
	window.sessionStorage.clear();
};
